<template>
	<div>
		<!--保额保费录入界面-->
		<el-dialog :title="title" :visible.sync="dialogVisible" size="small" :close-on-press-escape="false" :before-close="off" :top="dialog_margin_top">
			  <el-form label-width="160px" >
			  <el-row :span="24">
			  	<el-col :span="12">
			  		<el-form-item label="投保份数" required>
						<el-input v-model="kinditem.quantity" @keyup.native="checkNumber(15, 'quantity')" size="small"></el-input>
					</el-form-item>
					<el-form-item label="条款币别" required>
						<el-input v-model="kinditem.currency" disabled size="small"></el-input>
					</el-form-item>
					<el-form-item label="保额" required>
						<el-input v-model="kinditem.amount" @keyup.native="checkDecimal(12, 2, 'amount')" size="small"></el-input>
					</el-form-item>
					<el-form-item label="保费" required>
						<el-input v-model="kinditem.premium" @keyup.native="checkDecimal(12, 2, 'premium')" size="small"></el-input>
					</el-form-item>
					<el-form-item label="是否计入总保额" required>
						<el-select v-model="kinditem.calculateflag" size="small" >
							<el-option v-for="item in calculateflagOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
			  	</el-col>
			  	<el-col :span="12">
					<el-form-item label="单位保额" required>
						<el-input v-model="kinditem.unitamount" @keyup.native="checkDecimal(12, 2, 'unitamount')" size="small"></el-input>
					</el-form-item>
					<el-form-item label="单位保费" required>
						<el-input v-model="kinditem.unitpremium" @keyup.native="checkDecimal(12, 2, 'unitpremium')" size="small"></el-input>
					</el-form-item>
					<el-form-item label="最终费率(%)" required>
						<el-input v-model="kinditem.rate" @keyup.native="checkDecimal(5, 8, 'rate')" size="small"></el-input>
					</el-form-item>
					<el-form-item label="折扣率(%)" required>
						<el-input v-model="kinditem.discount" @keyup.native="checkDecimal(5, 8, 'discount')" size="small"></el-input>
					</el-form-item>
					<el-form-item label="责任归属" required>
						<el-select v-model="kinditem.ownerFlag" size="small" >
							<el-option v-for="item in ownerFlagOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
			  	</el-col>
			  </el-row>
			</el-form>
			  <span slot="footer" class="dialog-footer">
				   <el-button type="primary" @click="off">确 认</el-button>
			  </span>
		</el-dialog>
	</div>
</template>

<script>

import PlanAPI from "../../../../js/production/plan/planAPI"
import Validations from "../../../../js/production/validations"
export default {
	data() {
		return {
			dialogVisible: true,
			dialog_margin_top: '25%',
      itemNo:'',
			kinditem: {},
			title: '',
			calculateflagOptions : [
				{label : 'Y-是',value: 'Y'},
				{label : 'N-否',value: 'N'}
			],
			ownerFlagOptions: [
				{label : '0-司机',value: '0'},
				{label : '1-乘客',value: '1'},
				{label : '2-公共',value: '2'}
			]
		}
	},
	mounted() {
    this.itemNo = this.$parent.itemNo;
		this.kinditem = this.$parent.currentKindItem;
		// this.kinditem.calculateflag = this.$parent.currentKindItem.calculateflag.substring(0,1);
		if (typeof this.kinditem.itemcode === 'undefined' || this.kinditem.itemcode === null) {
			this.title = "【" + this.kinditem.kindcode + "-" + this.kinditem.kindcname + "】";
		} else {
			this.title = "【" + this.kinditem.kindcode + "-" + this.kinditem.kindcname + "-" + this.kinditem.itemcode + "-" + this.kinditem.itemcname + "】";

		}

    let kinditemsGroup = this.$parent.formData.kinditemsGroup;
    if (typeof kinditemsGroup === 'undefined') {
        let kinditems = this.$parent.formData.kinditems;
        for (let i = 0; i < kinditems.length; i++) {
          if (this.kinditem.kindcode === kinditems[i].kindcode && this.kinditem.itemcode === kinditems[i].itemcode) {
            kinditems[i] = this.kinditem;
          }
        }
    } else {
      for (let j = 0; j < kinditemsGroup[this.itemNo].length; j++) {
        if (this.kinditem.kindcode === kinditemsGroup[this.itemNo][j].kindcode && this.kinditem.itemcode === kinditemsGroup[this.itemNo][j].itemcode) {
          kinditemsGroup[this.itemNo][j] = this.kinditem;
        }
      }
    }
	},
	methods: {
		off() {
			this.$parent.showAmountPremiumAddDialog = false;
		},
		checkNumber(length, field) {
			Validations.checkNumber(length, this.kinditem, field);
		},
		checkDecimal(intLength, digitalLength, field) {
			Validations.checkDecimal(intLength, digitalLength, this.kinditem, field);
		},
	}
  }
</script>
